package com.sansecy.customview.view;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.sansecy.customview.R;

public class ImageDrawView extends View {
    private static final String TAG = "ImageDrawView-App";
    private Bitmap mBitmap;

    public ImageDrawView(Context context) {
        super(context);
    }

    public ImageDrawView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fastplan_ic_question);
//        setBackgroundColor(Color.WHITE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //这是要绘制到画布上的四个点的位置
        Rect dst = new Rect(0, 0, 100, 100);
        //指定取图片上的哪块地方绘制到屏幕
        Rect src = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
        canvas.drawBitmap(mBitmap, src, dst, null);
        Log.d(TAG, "onDraw: " + dst.toString());
    }
}
